using UnityEngine;

public class CharacterMovement : MonoBehaviour
{
	public Rigidbody rigsToMove;

	[SerializeField]
	private Rigidbody[] rigidbodies;

	[SerializeField]
	private Rigidbody[] rigsToDown;

	public float forceMultiplier;

	public float jumpForceMultiplier;

	public float jumpTime = 0.5f;

	[SerializeField]
	private CharacterStanding standing;

	[SerializeField]
	private CharacterInformation info;

	private CharacterRotation rotation;

	private void Start()
	{
		rigidbodies = GetComponentsInChildren<Rigidbody>();
		rotation = GetComponent<CharacterRotation>();
	}

	public void Move(float direction)
	{
		Rigidbody[] array = rigidbodies;
		rotation.lookingRight = (direction < 0f);
		direction = Mathf.Sign(direction);
		Rigidbody[] array2 = array;
		foreach (Rigidbody rigidbody in array2)
		{
			rigidbody.AddForce(direction * Vector3.forward * forceMultiplier * Time.deltaTime, ForceMode.Acceleration);
		}
		rigsToMove.AddForce(direction * Vector3.forward * 700f * Time.deltaTime, ForceMode.Acceleration);
	}

	public void Jump(bool force = false, bool forceWallJump = false)
	{
		info.PlayJump();
		standing.gravity = jumpTime * 0.5f;
		float d = 0.3f;
		info.GetComponent<CharacterParticles>().PlayJumpEffect(info.mainRig.position);
		Rigidbody[] array = rigidbodies;
		foreach (Rigidbody rigidbody in array)
		{
			Rigidbody rigidbody2 = rigidbody;
			Vector3 velocity = rigidbody.velocity;
			float x = velocity.x;
			Vector3 velocity2 = rigidbody.velocity;
			rigidbody2.velocity = new Vector3(x, 0f, velocity2.z);
			if (!force)
			{
				if (info.wallNormal != Vector3.zero)
				{
					rigidbody.AddForce(info.wallNormal * jumpForceMultiplier * 0.75f, ForceMode.VelocityChange);
					rigidbody.AddForce(Vector3.up * jumpForceMultiplier * 0.85f, ForceMode.VelocityChange);
				}
				else
				{
					rigidbody.AddForce(Vector3.up * jumpForceMultiplier, ForceMode.VelocityChange);
				}
			}
			else if (forceWallJump)
			{
				rigidbody.AddForce(info.wallNormal * d * jumpForceMultiplier * 0.75f, ForceMode.VelocityChange);
				rigidbody.AddForce(Vector3.up * d * jumpForceMultiplier * 0.85f, ForceMode.VelocityChange);
			}
			else
			{
				rigidbody.AddForce(Vector3.up * d * jumpForceMultiplier, ForceMode.VelocityChange);
			}
		}
		info.wallNormal = Vector3.zero;
		CameraShakeController.Instance.AddShake(Vector3.down);
	}

	public void Sit()
	{
		Rigidbody[] array = rigsToDown;
		foreach (Rigidbody rigidbody in array)
		{
			rigidbody.AddForce(Vector3.down * jumpForceMultiplier * 0.85f, ForceMode.VelocityChange);
		}
	}
}
